<% layout('/layouts/default.html', {title: '车辆结算明细报表', libs: ['validate','dataGrid']}){ %>

<div class="main-content">
    <div class="box box-main">
        <div class="box-header with-border">
            <div class="box-title">
                <i class="fa icon-note"></i> ${text('车辆结算明细报表')}
            </div>
            <div class="box-tools pull-right">
                <button type="button" class="btn btn-sm btn-default"  onclick="submitTabCustom()">${text('客户结算')}</button>
                <a href="#" id="btnCustom"
                   class="btn btn-primary addTabPage" title="${text('编辑客户结算单')}" style="display:none;"></a>
                <button type="button" class="btn btn-sm btn-default"  onclick="submitTabZF()">${text('资方结算')}</button>
                <a href="#" id="btnZF"
                   class="btn btn-primary addTabPage" title="${text('编辑资方结算单')}"
style="display:none;"></a>
            </div>
        </div>
        <#form:form id="inputForm" model="${customerSettlement}" action="${ctx}/settlement/customersettlement/customerSettlement/save" method="post" class="form-horizontal">
        <div class="box-body">
            <div class="form-unit">${text('查询条件')}</div>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group " >
                        <label class="control-label col-sm-4" title="">
                            <span class="required hidden">*</span> ${text('服务订单创建日期')}：<i class="fa icon-question hide"></i></label>
                            <div class="row">
                            <div class="col-sm-2">
                                <#form:input path="createDate_gte" readonly="true" maxlength="20" class="form-control laydate width-date"
                                dataFormat="date" data-type="date" data-format="yyyy-MM-dd" data-done="createDate_lte.click()"  onchange="serviceOrderChange()"/>
                            </div>
                            <div class="col-sm-2" style="width:30px;">
                                <div style="padding-left:15px;">-</div>
                            </div>
                            <div class="col-sm-2">
                                <#form:input path="createDate_lte" readonly="true" maxlength="20" class="form-control laydate width-date"
                                dataFormat="date" data-type="date" data-format="yyyy-MM-dd" onchange="serviceOrderChange()"/>
                            </div>
                            </div>
                    </div>
                </div>
                <div class="col-xs-4" style="padding-left:15px;">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required hidden">*</span> ${text('客户')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:select path="customerId" items="${customerList}" itemLabel="customerName"
                            itemValue="customerId" blankOption="true" class="form-control required" onchange="serviceOrderChange()"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required hidden">*</span> ${text('资方')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:select path="investorId" items="${gnzfList}" itemLabel="supplierName" itemValue="supplierId"
                            class="form-control required" blankOption="true" onchange="serviceOrderChange()"/>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="control-label col-sm-4" title="">
                            <span class="required">*</span> ${text('服务订单编号')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:select path="serviceOrderId"  items="${serviceOrderList}" itemLabel="serviceOrderCode"
                            itemValue="serviceOrderId" blankOption="true" class="form-control required" onchange="searchTab1()"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-12">
                    <div style="text-align:center;width:100%;">
                        <div>
                            <button type="button" class="btn btn-sm btn-default" id="btnSearch" onclick="searchTab1()">${text('查 询')}</button>
                            <button type="button" class="btn btn-sm btn-default" id="btnReset" onclick="resetTab1()">${text('重 置')}</button>
                        </div>
                    </div>
                </div>
            </div>

            <h4 class="form-unit">${text('合计信息')}</h4>
            <div class="ml10 mr10">
                <table id="mainDataGrid"></table>
            </div>

            <h4 class="form-unit">${text('预收款信息')}</h4>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group " >
                        <label class="control-label col-sm-4" title="">
                            <span class="required hidden">*</span> ${text('预收客户余额')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="advancedReceivedBalance" class="form-control required number" readonly="true"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="ml10 mr10">
                <table id="preGainDataGrid"></table>
            </div>

            <h4 class="form-unit">${text('预付款信息')}</h4>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group " >
                        <label class="control-label col-sm-4" title="">
                            <span class="required hidden">*</span> ${text('预付资方余额')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:input path="paymentAmountEstimatedBalance" class="form-control required number" readonly="true"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="ml10 mr10">
                <table id="prePayDataGrid"></table>
            </div>

            <h4 class="form-unit">${text('收款信息')}</h4>
            <div class="ml10 mr10">
                <table id="gainInfoDataGrid"></table>
            </div>

            <h4 class="form-unit">${text('付款信息')}</h4>
            <div class="ml10 mr10">
                <table id="payInfoDataGrid"></table>
            </div>

        <div class="box-footer">
            <div class="row">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
                </div>
            </div>
        </div>
    </#form:form>
</div>
</div>
<% } %>
<script>
    //合计信息
    $('#mainDataGrid').dataGrid({
        datatype: "local", // 设置本地数据
        autoGridHeight: function(){return 'auto'}, // 设置自动高度
        columnModel: [
            {header:'${text("勾选")}',name:'tabId', width:60, editable:true, edittype:'checkbox'},
            {header:'${text("已客户结算")}',name:'customerStatus', width:150, editable:false, edittype:'text'},
            {header:'${text("已资方结算")}',name:'investorStatus', width:150, editable:false, edittype:'text'},
            {header:'${text("物流是否已完结")}',name:'lockFlag', width:150, editable:false, edittype:'text'},
            {header:'${text("车辆名称")}', name:'carName', width:350, editable:false, edittype:'text', editoptions:{'class':'form-control'}},
            {header:'${text("车架号")}', name:'frameNumber', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control'}},
            {header:'${text("车价(外币)")}', name:'amount', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control'}},
            {header:'${text("币种")}', name:'currency', width:100, editable:false, edittype:'text', editoptions:{'class':'form-control'},formatter: function(val, obj, row, act){
                    return js.getDictLabel(${@DictUtils.getDictListJson('sys_bizhong')}, val, '${text("未知")}', true);}},
            {header:'${text("预计汇率")}',name:'tentativeExchangeRate', width:120, editable:false, edittype:'text',},
            {header: '${text("实际汇率")}',name:'investorRealExchangeRate', width:120, editable:false, edittype:'text',},
            {header: '${text("客户-应收总金额(RMB)")}',name:'rApAmount', width:150, editable:false, edittype:'text',},
            {header: '${text("客户-实收总金额(RMB)")}',name:'rActualApAmount', width:150, editable:false, edittype:'text',},
            {header: '${text("资方-应付总金额(RMB)")}',name:'pApAmount', width:150, editable:false, edittype:'text',},
            {header: '${text("资方-实付总金额(RMB)")}',name:'pActualApAmount', width:150, editable:false, edittype:'text',},
            {header: '${text("利润(RMB)")}',name:'gainAmount', width:150, editable:false, edittype:'text',}
        ],
        showFooter:true,
        // 加载成功后执行事件
        ajaxSuccess: function(data){
        }
    });

    //预收款信息
    $('#preGainDataGrid').dataGrid({
        datatype: "local", // 设置本地数据
        autoGridHeight: function(){return 'auto'}, // 设置自动高度
        columnModel: [
            {header:'${text("车架号")}', name:'frameNumber', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control'}},
            {header:'${text("预收款单号")}', name:'advancesReceivedCode', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control'}},
            {header: '${text("日期")}',name:'dateStr', width:150, editable:false,  formatter:'date'},
            {header: '${text("预收款类型")}',name:'advancesReceivedTypeName', width:150, editable:false, edittype:'text',},
            {header: '${text("金额")}',name:'receivedSumActual', width:150, editable:false, edittype:'text',},
            {header: '${text("已核销金额")}',name:'receivedAmountActual', width:150, editable:false, edittype:'text',},
            {header: '${text("剩余金额")}',name:'receivedAmountEstimated', width:150, editable:false, edittype:'text',}
        ],
        // 加载成功后执行事件
        ajaxSuccess: function(data){
        }
    });

    //预付款信息
    $('#prePayDataGrid').dataGrid({
        datatype: "local", // 设置本地数据
        autoGridHeight: function(){return 'auto'}, // 设置自动高度
        columnModel: [
            {header:'${text("车架号")}', name:'frameNumber', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control'}},
            {header:'${text("预付款单号")}', name:'prepaymentCode', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control'}},
            {header:'${text("日期")}',name:'dateStr', width:150, editable:false,  formatter:'text'},
            {header:'${text("预付款类型")}', name:'prepaymentTypeName', width:150,editable:false, edittype:'text'},
            {header:'${text("金额")}',name:'paymentSumActual', width:150, editable:false, edittype:'text',},
            {header:'${text("已核销金额")}',name:'paymentAmountActual', width:150, editable:false, edittype:'text',},
            {header:'${text("剩余金额")}',name:'paymentAmountEstimated', width:150, editable:false, edittype:'text',}
        ],
        // 加载成功后执行事件
        ajaxSuccess: function(data){
        }
    });

    //收款信息
    $('#gainInfoDataGrid').dataGrid({
        datatype: "local", // 设置本地数据
        autoGridHeight: function(){return 'auto'}, // 设置自动高度
        columnModel: [
            {header:'${text("车辆名称")}', name:'carName', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control'}},
            {header:'${text("车架号")}', name:'frameNumber', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control'}},
            {header:'${text("收款单号")}', name:'receivableCode', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control'}},
            {header: '${text("费用项目")}',name:'expenseItemName', width:150, editable:false, edittype:'text',},
            {header: '${text("实收金额")}',name:'actualArAmount', width:150, editable:false, edittype:'text',},
            {header: '${text("是否是核销预收款")}',name:'advancesReceivedCode', width:150, editable:false, edittype:'text',}
        ],
        showFooter:true,
        // 加载成功后执行事件
        ajaxSuccess: function(data){
        }
    });

    //付款信息
    $('#payInfoDataGrid').dataGrid({
        datatype: "local", // 设置本地数据
        autoGridHeight: function(){return 'auto'}, // 设置自动高度
        columnModel: [
            {header:'${text("车辆名称")}', name:'carName', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control'}},
            {header:'${text("车架号")}', name:'frameNumber', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control'}},
            {header:'${text("付款单号")}', name:'paymentCode', width:150, editable:false, edittype:'text', editoptions:{'class':'form-control'}},
            {header: '${text("费用项目")}',name:'expenseItemName', width:150, editable:false, edittype:'text',},
            {header: '${text("实付金额")}',name:'actualApAmount', width:150, editable:false, edittype:'text',},
            {header: '${text("是否是核销预收款")}',name:'prepaymentCode', width:150, editable:false, edittype:'text',}
        ],
        showFooter:true,
        // 加载成功后执行事件
        ajaxSuccess: function(data){

        }
    });
</script>
<script>
    function onCheck(){
        let rowDatas = $("#mainDataGrid").jqGrid("getRowData");
        let rowIds = $('#mainDataGrid').dataGrid('getDataIDs');
        let frameNumbersStr = "";
        for (let i = 1; i <= rowDatas.length; i++) {
            let rowData = rowDatas[i-1];
            let frameNumber = rowData.frameNumber;
            let rowId = rowIds[i-1];
            let checkBox = $("input[rowid='"+rowId+"']");
            let flag = $(checkBox).is(":checked");
            if(flag){
                frameNumbersStr = frameNumbersStr + frameNumber + ","
            }
        }
        frameNumbersStr = frameNumbersStr.substring(0,frameNumbersStr.length-1);
        if(frameNumbersStr.length == 0) {
            return false;
        }

        $.ajax({
            type: "post",
            url: "${ctx}/settlement/carpresettlement/carPreSettlement/getPayInfoTables",
            data: {frameNumbers:frameNumbersStr},
            dataType: "json",
            success: function(data){
                if(data == null){
                    js.showMessage("请确认前置单据是否正确");
                    return
                }

                var list1 = data.tadvancesReceivedEstimatedList;
                $("#advancedReceivedBalance").val(data.advancedReceivedBalance);
                var list2 = data.tprepaymentEstimatedList;
                $("#paymentAmountEstimatedBalance").val(data.paymentAmountEstimatedBalance);
                var list3 = data.treceivableDetailList;
                var list4 = data.tpayList;

                var ids1 = $("#preGainDataGrid").getDataIDs();
                for (var i = 0; i < ids1.length ; i++) {
                    $('#preGainDataGrid').dataGrid('delRowData', ids1[i]);
                }
                for(let i=0;i<list1.length;i++) {
                    $("#preGainDataGrid").jqGrid("addRow", {
                        position: "last",
                        addRowParams: {keys: false, focusField: true, selected:false},
                        initdata: {
                            frameNumber: list1[i].frameNumber,
                            advancesReceivedCode:list1[i].advancesReceivedCode,
                            carName: list1[i].carName,
                            advancesReceivedTypeName: list1[i].advancesReceivedTypeName,
                            receivedSumActual: list1[i].receivedSumActual,
                            receivedAmountActual: list1[i].receivedAmountActual,
                            receivedAmountEstimated: list1[i].receivedAmountEstimated,
                            dateStr: list1[i].dateStr
                        }
                    });
                }

                var ids2 = $("#prePayDataGrid").getDataIDs();
                for (var i = 0; i < ids2.length ; i++) {
                    $('#prePayDataGrid').dataGrid('delRowData', ids2[i]);
                }
                for(let i=0;i<list2.length;i++) {
                    $("#prePayDataGrid").jqGrid("addRow", {
                        position: "last",
                        addRowParams: {keys: false, focusField: true, selected:false},
                        initdata: {
                            frameNumber: list2[i].frameNumber,
                            prepaymentCode:list2[i].prepaymentCode,
                            carName: list2[i].carName,
                            prepaymentTypeName: list2[i].prepaymentTypeName,
                            paymentSumActual: list2[i].paymentSumActual,
                            paymentAmountActual: list2[i].paymentAmountActual,
                            paymentAmountEstimated: list2[i].paymentAmountEstimated,
                            dateStr: list2[i].dateStr
                        }
                    });
                }

                var ids3 = $("#gainInfoDataGrid").getDataIDs();
                for (var i = 0; i < ids3.length ; i++) {
                    $('#gainInfoDataGrid').dataGrid('delRowData', ids3[i]);
                }
                var maxp3 = 0;
                for(let i=0;i<list3.length;i++) {
                    $("#gainInfoDataGrid").jqGrid("addRow", {
                        position: "last",
                        addRowParams: {keys: false, focusField: true, selected:false},
                        initdata: {
                            carName: list3[i].carName,
                            frameNumber: list3[i].frameNumber,
                            receivableCode:list3[i].receivableCode,
                            expenseItemName: list3[i].expenseItemName,
                            actualArAmount: list3[i].actualArAmount,
                            advancesReceivedCode: list3[i].advancesReceivedCode
                        }
                    });
                    maxp3 = maxp3 + (list3[i].actualArAmount==null?0:list3[i].actualArAmount);
                }
                // 设置底部合计行数据(设置合计行)
                $('#payInfoDataGrid').dataGrid("footerData", "set", {
                    'expenseItem' : '合计：',
                    'actualArAmount':maxp3
                }, false);

                var ids4 = $("#payInfoDataGrid").getDataIDs();
                for (var i = 0; i < ids4.length ; i++) {
                    $('#payInfoDataGrid').dataGrid('delRowData', ids4[i]);
                }
                var maxp4 = 0;
                for(let i=0;i<list4.length;i++) {
                    $("#payInfoDataGrid").jqGrid("addRow", {
                        position: "last",
                        addRowParams: {keys: false, focusField: true, selected:false},
                        initdata: {
                            carName: list4[i].carName,
                            frameNumber: list4[i].frameNumber,
                            paymentCode:list4[i].paymentCode,
                            expenseItemName: list4[i].expenseItemName,
                            actualApAmount: list4[i].actualApAmount,
                            prepaymentCode: list4[i].prepaymentCode
                        }
                    });
                    maxp4 = maxp4 + (list4[i].actualApAmount==null?0:list4[i].actualApAmount);
                }
                // 设置底部合计行数据(设置合计行)
                $('#payInfoDataGrid').dataGrid("footerData", "set", {
                    'expenseItem' : '合计：',
                    'actualApAmount':maxp4
                }, false);
            }
        });
    }
    function serviceOrderChange(){
        $.ajax({
            type: "POST",
            url: "${ctx}/settlement/carpresettlement/carPreSettlement/getServiceOrderList2",
            data: {"customerId": $("#customerId").val(),"investorId":$("#investorId").val(),"createDate_gte" : $("#createDate_gte").val(), "createDate_lte" : $("#createDate_lte").val()},
            success: function (data) {
                $("#serviceOrderId").empty();
                if (data.length > 0) {
                    for (let i = 0; i < data.length; i++) {
                        let partId = data[i].serviceOrderId;
                        let partName = data[i].serviceOrderCode;
                        let option = $("<option>").attr({
                            "value" : partId
                        }).text(partName);
                        $("#serviceOrderId").append(option);
                    }
                    $("#serviceOrderId option:first").prop("selected", 'selected');
                    $("#serviceOrderId").change();
                }
                if(data == ""){
                    js.showErrorMessage("该客户没有服务订单！");
                }
            }
        });
    }
    function submitCheck(sflag){
        let rowDatas = $("#mainDataGrid").jqGrid("getRowData");
        let rowIds = $('#mainDataGrid').dataGrid('getDataIDs');
        let frameNumbersStr = "";
        for (let i = 1; i <= rowDatas.length; i++) {
            let rowData = rowDatas[i-1];
            let frameNumber = rowData.frameNumber;
            let rowId = rowIds[i-1];
            let checkBox = $("input[rowid='"+rowId+"']");
            let flag = $(checkBox).is(":checked");
            if(flag){
                let customerStatus = rowData.customerStatus;
                let investorStatus = rowData.investorStatus;
                if(sflag == "1" && customerStatus == "已结算"){
                    js.showErrorMessage("已客户结算请取消勾选！");
                    return "false";
                }
                if(sflag == "2" && investorStatus == "已结算"){
                    js.showErrorMessage("已资方结算请取消勾选！");
                    return "false";
                }
                frameNumbersStr = frameNumbersStr + frameNumber + ","
            }
        }
        frameNumbersStr = frameNumbersStr.substring(0,frameNumbersStr.length-1);
        if(frameNumbersStr == "" || frameNumbersStr == null){
            js.showErrorMessage("请勾选数据！");
            return "false";
        }
        return frameNumbersStr;
    }

    function submitTabCustom(){
        let frameNumbersStr = submitCheck("1");
        if(frameNumbersStr == "false"){
            return;
        }

        let serviceOrderId = $("#serviceOrderId").val();
        if(serviceOrderId == null || serviceOrderId == ""){
            js.showErrorMessage("服务订单不能为空");
            return false;
        }

        let customerId = $("#customerId").val();
        if(customerId == null || customerId == ""){
            js.showErrorMessage("客户不能为空");
            return false;
        }

        //生成客户结算单数据-获取id-更改url-触发点击事件
        $.ajax({
            type: "POST",
            url: "${ctx}/settlement/customersettlement/customerSettlement/submitSave",
            data: {"serviceOrderId": serviceOrderId,"frameNumbersStr":frameNumbersStr},
            async: true,
            success: function (data) {
                console.info("data:"+data);
                if(data == ""){
                    js.showErrorMessage("生成客户结算单失败");
                    return false;
                }
                searchTab1();
                $("#btnCustom").attr("href","${ctx}/settlement/customersettlement/customerSettlement/form?customerSettlementId="+data);
                $("#btnCustom").click();
            }
        });

        /*$("#btnCustom").attr("href","${ctx}/settlement/customersettlement/customerSettlement/form?customerSettlementId=1379045888072527872");
        $("#btnCustom").click();*/

    }

    function submitTabZF(){
        let frameNumbersStr = submitCheck("2");
        if(frameNumbersStr == "false"){
            return false;
        }

        let serviceOrderId = $("#serviceOrderId").val();
        if(serviceOrderId == null || serviceOrderId == ""){
            js.showErrorMessage("服务订单不能为空");
            return false;
        }

        let investorId = $("#investorId").val();
        if(investorId == null || investorId == ""){
            js.showErrorMessage("资方不能为空");
            return false;
        }

        $.ajax({
            type: "POST",
            url: "${ctx}/settlement/investorsettlement/investorSettlement/submitSave",
            data: {"serviceOrderId": serviceOrderId,"frameNumbersStr":frameNumbersStr},
            async: true,
            success: function (data) {
                if(data == ""){
                    js.showErrorMessage("生成资方结算单失败");
                    return false;
                }
                searchTab1();
                $("#btnZF").attr("href","${ctx}/settlement/investorsettlement/investorSettlement/form?investorSettlementId="+data);
                $("#btnZF").click();
            }
        });
    }

    function searchTab1(){
        let serviceOrderId = $("#serviceOrderId").val();
        if(serviceOrderId==null || serviceOrderId==""){
            js.showErrorMessage("服务订单未选择！");
            return;
        }
        let data ={"serviceOrderId":$("#serviceOrderId").val()}
        $.ajax({
            type: "post",
            url: "${ctx}/settlement/carpresettlement/carPreSettlement/getTableData",
            data: data,
            dataType: "json",
            success: function(data){
                if(data == null){
                    js.showMessage("请确认信息是否正确");
                    return;
                }
                var ids1 = $("#mainDataGrid").getDataIDs();
                for (var i = 0; i < ids1.length ; i++) {
                    $('#mainDataGrid').dataGrid('delRowData', ids1[i]);
                }
                var max1 = 0;
                var max2 = 0;
                var max3 = 0;
                var max4 = 0;
                var max5 = 0;
                for(let i=0;i<data.length;i++) {
                    max1 = max1 + (data[i].rApAmount==null?0:data[i].rApAmount);
                    max2 = max2 + (data[i].rActualApAmount==null?0:data[i].rActualApAmount);
                    max3 = max3 + (data[i].pApAmount==null?0:data[i].pApAmount);
                    max4 = max4 + (data[i].pActualApAmount==null?0:data[i].pActualApAmount);
                    max5 = max5 + (data[i].gainAmount==null?0:data[i].gainAmount);

                    $("#mainDataGrid").jqGrid("addRow", {
                        position: "last",
                        addRowParams: {keys: false, focusField: true, selected:false},
                        initdata: {
                            customerStatus: data[i].customerStatus,
                            investorStatus:data[i].investorStatus,
                            lockFlag:data[i].lockFlag,
                            date: data[i].date,
                            carName: data[i].carName,
                            frameNumber: data[i].frameNumber,
                            amount: data[i].amount,
                            currency: data[i].currency,
                            tentativeExchangeRate: data[i].tentativeExchangeRate,
                            investorRealExchangeRate: data[i].investorRealExchangeRate,
                            rApAmount: data[i].rApAmount,
                            rActualApAmount: data[i].rActualApAmount,
                            pApAmount: data[i].pApAmount,
                            pActualApAmount: data[i].pActualApAmount,
                            gainAmount:data[i].gainAmount
                        }
                    });
                }

                let rowDatas = $("#mainDataGrid").jqGrid("getRowData");
                let rowIds = $('#mainDataGrid').dataGrid('getDataIDs');
                for (let i = 1; i <= rowDatas.length; i++) {
                    let rowData = rowDatas[i-1];
                    let rowId = rowIds[i-1];
                    let checkBox = $("input[rowid='"+rowId+"']");
                    let lockFlag = rowData.lockFlag;
                    if(lockFlag == '未完结'){
                        $(checkBox).prop("disabled",true);
                    }
                }

                $("#mainDataGrid").on("click", 'tr[role="row"]', function() {
                    onCheck();
                });

                // 设置底部合计行数据(设置合计行)
                $('#mainDataGrid').dataGrid("footerData", "set", {
                    'frameNumber' : '合计：',
                    'rApAmount':max1,
                    'rActualApAmount':max2,
                    'pApAmount':max3,
                    'pActualApAmount':max4,
                    'gainAmount':max5
                }, false);

                //清空其余款项列表
                $('#preGainDataGrid').jqGrid('clearGridData');
                $('#prePayDataGrid').jqGrid('clearGridData');
                $('#gainInfoDataGrid').jqGrid('clearGridData');
                $('#payInfoDataGrid').jqGrid('clearGridData');
            }
        });
    }
    function resetTab1(){
        $('#mainDataGrid').jqGrid('clearGridData');
        $('#preGainDataGrid').jqGrid('clearGridData');
        $('#prePayDataGrid').jqGrid('clearGridData');
        $('#gainInfoDataGrid').jqGrid('clearGridData');
        $('#payInfoDataGrid').jqGrid('clearGridData');
    }
</script>
